package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.ShareholderShouldPay;
import cn.net.shuxing.yifu.common.mapper.ShareholderShouldPayMapper;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShareholderShouldPayService extends BaseService<ShareholderShouldPay,ShareholderShouldPayMapper> {



    public List<ShareholderShouldPay> getsByShareholderId(Integer shareholderId)
    {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("shareholderId",shareholderId);
        List<ShareholderShouldPay> shareholderShouldPayList = gets(paramMap);
        shareholderShouldPayList.forEach((x)->{complete(x);});
        return shareholderShouldPayList;
    }

    @Override
    protected void complete(ShareholderShouldPay bean)
    {
        if (bean == null)
            return;
        if (bean.getSettledCount().compareTo(bean.getShouldCount()) >= 0)
        {
            bean.setComplete(true);
        }
        else
        {
            bean.setComplete(false);
        }
    }


    public ShareholderShouldPay insert(Integer shareholderId, LocalDateTime latestPayTime, BigDecimal cashCount )
    {
        ShareholderShouldPay shareholderShouldPay = new ShareholderShouldPay();
        shareholderShouldPay.setOverdue(0);
        shareholderShouldPay.setShareholderId(shareholderId);
        shareholderShouldPay.setLatestPayTime(latestPayTime);
        shareholderShouldPay.setShouldCount(cashCount);
        shareholderShouldPay.setShareholderId(shareholderId);
        shareholderShouldPay.setSettledCount(new BigDecimal(0));
        insert(shareholderShouldPay);
        return getByPrimaryKey(shareholderShouldPay.getId());
    }
}
